<?php
namespace app\common\model;
use x\Xbase;
    
#推广奖
class Awardtuiguang extends Xbase
{  	
	/**
	 * 推广奖
	 * @param  [type] $order_data [user_vip]
	 * @param  [type] $order_id   [user_vip_id]
	 * @param  [type] $level      [升级级别]
	 * @return [type]             [description]
	 */
    public function doit($order_data,$order_id,$level=1){
        exit('废弃');
    	$user_id = 0;
    	$money = 0;
    	switch ($level) {
    		case 1:
    			$user_id = $order_data['vip_user_id'];
    			$money = $order_data['vip_money'];
    			break;
    		case 2:
    			$user_id = $order_data['lingshou_user_id'];
    			$money = $order_data['lingshou_money'];
    			break;
    		case 3:
    			$user_id = $order_data['pifa_user_id'];
    			$money = $order_data['pifa_money'];
    			break;
    		case 4:
    			$user_id = $order_data['daili_user_id'];
    			$money = $order_data['daili_money'];
    			break;
    	}
    	if ($user_id==0 || $money==0) return true;

    	$fee = 0;
        $real_money = bcsub($money,$fee,2);
    	$mysql = [];
    	$data = [
    		'order_no' => $this->com_order_no(),
            'user_vip_id' => $order_id,
    		'user_id' => $user_id,
    		'level' => $level,
            'money' => $money,
            'fee' => $fee,
            'status' => 1,
            'note' => '获得推广奖',
            'real_money' => $real_money,
    		'create_time' => time(),
    	];
        $mysql[] = $id = $this->db->insert('award_tuiguang',$data);

        $mysql[] = m('Userbill','xcom')->doit($data['order_no'],$data['user_id'],110,'award_tuiguang',$id,$data['real_money'],'money_sy','获得推广奖');

        foreach($mysql as $v){if(!$v) return false;}return true;

    }
}
